<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>
<div id="app">
    <input type="text" placeholder="员工id" v-model="job.id">id<br>
    <input type="text" v-model="job.info" placeholder="岗位">岗位<br>
    <input type="text" placeholder="员工姓名" v-model="job.name">姓名<br>
    <div v-if="job.info=='销售'">
        <input type="text" placeholder="基本工资" v-model="job.baseSal">基本工资
        <input type="text" placeholder="销售额" v-model="job.saleCount">销售额
        <input type="text" :placeholder="job.saleCount*0.01" readonly v-model="job.bonus">奖金
        <input type="text" :placeholder="job.saleCount*0.01+job.baseSal*1" readonly v-model="job.endSal">最终工资
    </div>
    <div v-else-if="job.info=='技术'">
        <input type="text" placeholder="基本工资" v-model="job.baseSal">基本工资
        <input type="text" placeholder="绩点" v-model="job.score">绩点
        <input type="text" placeholder="奖金" readonly v-model="job.bonus">奖金
        <input type="text" placeholder="最终工资" readonly v-model="job.endSal">最终工资
    </div>
    <div v-else>
        <input type="text" placeholder="基本工资" v-model="job.baseSal">基本工资
        <input type="text" placeholder="奖金" readonly v-model="job.bonus">奖金
        <input type="text" placeholder="最终工资" readonly v-model="job.endSal">最终工资
    </div>
    <input type="button" value="提交" @click="add()">
</div>
</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function() {
            return {
                arr:["销售","技术","后勤"],
                job:{
                    id:"",
                    name:"",
                    info:"",//岗位
                    baseSal:"",//基本工资
                    saleCount:"",//销售额
                    bonus:"",//奖金
                    score:"",//绩点
                    endSal:""//最终工资
                }
            }
        },
        methods:{
            add(){
                if (v.job.info=="销售"){
                    v.job.bonus=v.job.saleCount*0.01;
                    v.job.endSal=(v.job.bonus*1+v.job.baseSal*1);

                    console.log("id="+v.job.id)
                    console.log("name="+v.job.name)
                    console.log("info="+v.job.info)
                    console.log("baseSal="+v.job.baseSal)
                    console.log("saleCount="+v.job.saleCount)
                    console.log("bonus="+v.job.bonus)
                    console.log("score="+v.job.score)
                    console.log("endSal="+v.job.endSal)
                }else if (v.job.info=="技术"){
                    let a ;
                    if (v.job.score<0.6){
                        a=0;
                    }else if (v.job.score<0.8){
                        a=0.7;
                    }else if (v.job.score<0.9){
                        a=1;
                    }else {
                        a=1.5;
                    }
                    v.job.bonus=v.job.baseSal*0.2*a;
                    v.job.endSal = v.job.bonus*1+v.job.baseSal*1;
                    console.log("id="+v.job.id)
                    console.log("name="+v.job.name)
                    console.log("info="+v.job.info)
                    console.log("baseSal="+v.job.baseSal)
                    console.log("saleCount="+v.job.saleCount)
                    console.log("bonus="+v.job.bonus)
                    console.log("score="+v.job.score)
                    console.log("endSal="+v.job.endSal)
                }else if (v.job.info=="后勤"){
                    //如果是后勤,需要先查找平均奖金
                    axios.get("/selectAvgSal").then(function (response) {
                        v.job.bonus=response.data*1;
                        v.job.endSal=(v.job.bonus*1+v.job.baseSal*1);
                    })
                    console.log("id="+v.job.id)
                    console.log("name="+v.job.name)
                    console.log("info="+v.job.info)
                    console.log("baseSal="+v.job.baseSal)
                    console.log("saleCount="+v.job.saleCount)
                    console.log("bonus="+v.job.bonus)
                    console.log("score="+v.job.score)
                    console.log("endSal="+v.job.endSal)
                }else {
                    alert("岗位填写错误!")
                    location.reload();
                }
                console.log("job=="+v.job)
                axios.post("/insert",v.job).then(function (response) {
                    alert("添加成功!");
                })
            }
        }
    })
</script>
</html>

